package com.ziyun.pop.web.modules.service.controller;

import com.utility.http.HttpUtils;
import com.ziyun.pop.common.utils.JsonUtils;
import io.renren.common.utils.R;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;



 /* 售后登记表
 *
 * @author llc
 * @email 787254039@qq.com
 * @date 2018-09-21 15:34:38
 */

@RestController
@RequestMapping("service/serviceregister")
public class ServiceEntryController {
    @Value("${erpApi}")
    private String erpApi ;

    /**
     * 列表
     */

   /* @RequestMapping("/list")
    @RequiresPermissions("service:serviceregister:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = serviceRegisterService.queryPage(params);

        return R.ok().put("page", page);
    }*/



    /**
     * 信息
     *//*

    @RequestMapping("/info/{srId}")
    @RequiresPermissions("service:serviceregister:info")
    public R info(@PathVariable("srId") Integer srId){
        ServiceRegisterEntity serviceRegister = serviceRegisterService.selectById(srId);
        ServiceOrderInfoVo serviceOrderInfoVo = serviceRegisterService.selectServiceOrderInfo(serviceRegister.getSrOrderId());

        //查询售后商品明细
        if(serviceRegister.getSrType().intValue() ==ServiceTypeEnum.SERVICE_RETURN_REFUND.toInt() ||
                serviceRegister.getSrType().intValue() ==ServiceTypeEnum.SERVICE_EXCHANGE_GOODS.toInt()){
            //涉及退换货才有商品明细
            List<Map<String,Object>> mapsOrderItem  = this.serviceReceiveGoodsService.selectMaps(new QueryWrapper<ServiceReceiveGoodsEntity>()
                    .setSqlSelect("stock_id as stockId, stock_name as stockName")
                    .eq("status", 0)
                    .eq("parent_id", 2));
        }


        return R.ok().put("serviceRegister", serviceRegister).
                put("serviceOrderInfoVo", serviceOrderInfoVo);
    }


    /**
     * 售后登记
     * @param orderId
     * @return
     */

    @RequestMapping("/getRegisterInfo/{orderId}")
    public R getRegisterInfo(@PathVariable("orderId") Long orderId){
        Map<String, Object> paramBodyMap = new HashMap<String, Object>();
        paramBodyMap.put("orderId",orderId);
        String url = erpApi + "/service/serviceregister/getRegisterInfo";
        String response =  HttpUtils.doPost(url,paramBodyMap);
        R rs = JsonUtils.string2Object(response, R.class);
        return rs;

    }

     /**
     * 保存
     *//*

    @RequestMapping("/save")
    @RequiresPermissions("service:serviceregister:save")
    public R save(@Valid @RequestBody ServiceRegisterVo serviceRegister){
        serviceRegisterService.saveRegister(serviceRegister);
        return R.ok();
    }

    */
/**
     * 添加售后责任
     * @param serviceRegister
     * @return
     *//*

    @RequestMapping("/addResponsibility")
    public R addResponsibility(@RequestBody ServiceRegisterEntity serviceRegister){
        serviceRegisterService.updateById(serviceRegister);
        return R.ok();
    }

    */
/**
     * 审核
     * @param serviceRegister
     * @return
     *//*

    @RequestMapping("/check")
    public R check(@RequestBody ServiceRegisterEntity serviceRegister){
        serviceRegisterService.check(serviceRegister);
        return R.ok();
    }

    */
/**
     * 修改
     *//*

    @RequestMapping("/update")
    @RequiresPermissions("service:serviceregister:update")
    public R update(@RequestBody ServiceRegisterEntity serviceRegister){
        ValidatorUtils.validateEntity(serviceRegister);
        serviceRegisterService.updateAllColumnById(serviceRegister);//全部更新
        
        return R.ok();
    }

    */
/**
     * 删除
     *//*

    @RequestMapping("/delete")
    @RequiresPermissions("service:serviceregister:delete")
    public R delete(@RequestBody Integer[] srIds){
        serviceRegisterService.deleteBatchIds(Arrays.asList(srIds));

        return R.ok();
    }
*/
}

